<?php

	// Closure Test

	class Cart {

		const PRODUCT_MILK = 1.00;
		const PRODUCT_EGGS = 2.00;
		const PRODUCT_BUTTER = 3.00;

		protected $products = [];

		// 加入
		public function add($product, $quticy)
		{
			$this->products[$product] = $quticy;
		}

		// 汇率
		public function totalAmount($tax = 0.2)
		{
			$total = 0;

			$callback = function($quticy, $product) use (&$total, $tax) {

				$upperProduct = "PRODUCT_".strtoupper($product);
				$price = constant("self::".$upperProduct);

				//$price = constant(__CLASS__."::PRODUCT_".strtoupper($product));
				
				$total += $price * $quticy * $tax;
			};

			array_walk($this->products, $callback);

			return $total;
		}

	}

	$cart = new Cart();

	$cart->add("milk", 2);
	$cart->add("eggs", 3);
	$total = $cart->totalAmount(0.8);

	var_dump($total);die;


?>